package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleAddParam;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQueryParam;
import cn.tedu.ivos.vehicle.service.VehicleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/vehicle/")
@Slf4j
@Tag(name = "车辆模块")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("select")
    @Operation(summary = "查询车辆")
    @ApiOperationSupport(order = 10)
    public JsonResult selectVehicle(VehicleQueryParam vehicleQueryParam){
        log.debug("vehicleQueryParam:{}", vehicleQueryParam);
        return JsonResult.ok(vehicleService.selectVehicle(vehicleQueryParam));
    }

    @PostMapping("save")
    @Operation(summary = "保存车辆")
    @ApiOperationSupport(order = 20)
    public JsonResult saveVehicle(@Validated VehicleAddParam vehicleAddParam){
        log.debug("保存车辆业务:vehicleAddParam{}",  vehicleAddParam);
        vehicleService.saveVehicle(vehicleAddParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    @Operation(summary = "删除车辆")
    @ApiOperationSupport(order = 30)
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除车辆业务");
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geofenceId}/{vehicleId}")
    @Operation(summary = "绑定车辆")
    @ApiOperationSupport(order = 40)
    public JsonResult bindGeofence(@PathVariable Long geofenceId, @PathVariable Long vehicleId){
        log.debug("绑定车辆业务");
        vehicleService.bindGeofence(geofenceId,  vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{vehicleId}")
    @Operation(summary = "解绑车辆")
    @ApiOperationSupport(order = 50)
    public JsonResult unbindGeofence(@PathVariable Long vehicleId){
        log.debug("解绑车辆业务");
        vehicleService.unbindGeofence(vehicleId);
        return JsonResult.ok();
    }

}
